Skip to content

Conversation

@qizwiz
Copy link
Contributor

@qizwiz qizwiz commented Sep 18, 2025

This PR fixes Issue #32637 where ChatPromptTemplate's save method was raising NotImplementedError instead of inheriting the working implementation from BasePromptTemplate.

Issue

The ChatPromptTemplate class was overriding the parent class's working save method with a stub that just raised NotImplementedError. This prevented users from saving ChatPromptTemplate instances to files, even though the parent class BasePromptTemplate has a fully functional save implementation.

Root Cause

In src/transformers/processing_utils.py line 1303, there was an override:

def save(self, file_path: Union[Path, str]) -> None:
    """Save prompt to file.

    Args:
        file_path: path to file.
    """
    raise NotImplementedError

Solution

The fix removes this override, allowing ChatPromptTemplate to inherit the working save method from BasePromptTemplate. This enables users to save ChatPromptTemplate instances to JSON/YAML files as expected.

Testing

Added a test case that verifies:

  1. ChatPromptTemplate.save() no longer raises NotImplementedError
  2. The saved file contains valid JSON with the expected structure
  3. The _type field is correctly set to 'chat'

Impact

This is a backward-compatible bug fix that restores expected functionality for ChatPromptTemplate serialization. Users can now save and load ChatPromptTemplate instances as documented, which is important for persisting prompt configurations.

Fixes #32637

…ntedError override

This PR fixes Issue langchain-ai#32637 where ChatPromptTemplate's save method was raising
NotImplementedError instead of inheriting the working implementation from
BasePromptTemplate.

The fix removes the override that was preventing inheritance of the parent class's
functional save method, allowing ChatPromptTemplate instances to be saved to
JSON/YAML files as expected.

Fixes langchain-ai#32637
@qizwiz qizwiz requested a review from eyurtsev as a code owner September 18, 2025 00:15
@vercel
Copy link

vercel bot commented Sep 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
langchain Ignored Ignored Preview Sep 18, 2025 0:15am

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 18, 2025

CodSpeed WallTime Performance Report

Merging #32997 will not alter performance

Comparing qizwiz:fix-chatprompttemplate-save (d1cdb00) with master (cc9a97a)1

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched

Footnotes

  1. No successful run was found on master (d5ba5d3) during the generation of this report, so cc9a97a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@mdrxy mdrxy changed the title fix: Enable save method for ChatPromptTemplate by removing NotImplementedError override fix(core): Enable save method for ChatPromptTemplate by removing NotImplementedError override Sep 18, 2025
@mdrxy mdrxy added the core Related to the package `langchain-core` label Sep 18, 2025
Copy link
Collaborator

@ccurme ccurme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing as duplicated with #33631.

@ccurme ccurme closed this Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Related to the package `langchain-core`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ChatPromptTemplate save() not implemented

3 participants